<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; utf-8">
    <title>我的中心</title>
    <%@ include file="../../static/top.jsp" %>

    <style>
        
        th{
        	min-width: 80px;
        }
    </style>
</head>
<body class="sticky-header">

<section> <!-- left side start-->
    <%@ include
            file="../../static/menu.jsp" %> <!-- left side end-->

    <!-- main content start-->
    <div class="main-content">

        <!-- header section start-->


        <%@ include file="../../static/header.jsp" %>

        <div class="wrapper">
			<div class="page-heading">
				<ul class="breadcrumb">
					<li><a href="#">数据处理</a></li>
					<li><a href="/action/my/m/toMyData?mid=a2&aid=ch21">我的数据</a></li>
					<li class="active">数据详情</li>
				</ul>
			</div>
            <div class="row">
                <div class="col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">我的采集数据</div>
                        <div class="panel-body">

                            <div class="col-md-12">

                                <form class="form-horizontal" role="form">
                                    <div class="form-group">

                                        <label for="username" class="col-sm-2 control-label">我的采集列表</label>

                                        <div class="col-sm-3 ">
                                            <select id="request" class="form-control"> </select>
                                        </div>
                                        <div class="col-sm-1 ">
                                            <button id="searchBtn" type="button" class="btn btn-success">查询</button>
                                        </div>
                                        <div class="btn-group ">
                                            <button data-toggle="dropdown" type="button"
                                                    class="btn btn-primary  dropdown-toggle">
                                                			导出 <span class="caret"></span>
                                            </button>
                                            <ul role="menu" class="dropdown-menu">
                                                <li id="exportExcel"><a href="javascript:void(0)">excel</a></li>
                                                <li id="exportCsv"><a href="javascript:void(0)">csv</a></li>
                                                <li id="exportJson"><a href="javascript:void(0)">json</a></li>

                                            </ul>
                                        </div>
                                        
                                    </div>

                                </form>

                            </div>

                            <div class="col-md-12">

                                <div class="panel ">
                                    <div class="panel-heading">采集数据列表</div>
                                    <div class="panel-body" style="overflow-x:scroll">
                                        <table class="table table-bordered table-striped table-condensed">
                                            <thead>
                                            <tr id="thead">

                                            </tr>
                                            </thead>
                                            <tbody id="tbody">


                                            </tbody>
                                        </table>

                                    </div>
                                </div>
                                <div class="paging">
									<ul class="pagination" id="Pagination">

									</ul>
								</div>


                            </div>
                        </div>
                    </div>
                </div>

            </div>

        </div>
        <!--body wrapper end-->


        <!--footer section start-->
        <%@ include file="../../static/footer.jsp" %>

        <!--footer section end-->

        
        
    </div>

    <!-- main content end--> </section>

<script type="text/javascript">
var JOB_STATUS = {
		
		0 : {
			name : "待采集",
			value : '0'
		},
		1 : {
			name : "采集中",
			value : '1'
		},
		2 : {
			name : "采集完成",
			value : '2'
		},
		3 : {
			name : "采集失败",
			value : '3'
		},
		4 : {
			name : "解析中",
			value : '4'
		},
		5 : {
			name : "解析完成",
			value : '5'
		},
		6 : {
			name : "解析失败",
			value : '6'
		},
		
		"length" : 7
	};
    var tps = ${tps};
    var request_id = '${request_id}';
    var pageSize = 20, pageinit = true;	
    
    var ts = ${ts};
    if (ts && ts.length > 0) {
    
        for (var i = 0; i < ts.length; i++) {
            $("#thead").append("<th>" + ts[i].title + "</th>");
        }
    
    }

    function queryList(page, pageinit) {
    	$("#tbody").empty();
    	
    	$.get("/action/my/m/getMyTmpData",{"request_id":request_id,"pageNum" : page,"pageSize" : pageSize},function(list){
    	
    		 var _totalPage = list.maxPage;
    		 var tbody = "";
    	     if (list.data && list.data.length > 0) {
    	            var rows = list.data;
    	            for (var i = 0; i < rows.length; i++) {
    	                var row = rows[i];
    	                var link = row["link"];
    	                tbody += "<tr>"
    	                for (var j = 0; j < ts.length; j++) {
    	                    var key = ts[j].prop;
    	                    if(key=='link'){
    	                    	continue;
    	                    }
    	                  
    	                    var val = row[key];
    	                    if (val == undefined || val == null || val == 'null') {
    	                        tbody += "<td  class='tdspan'></td>"
    	                    } else {
    	                    	if(link){
    	                    		var linkVal = link[key];
        	                    	if(linkVal != undefined && linkVal != null && linkVal != 'null'){
        	                    		 tbody += "<td  class='tdspan'><a href='javascript:void(0)' onclick='linkPage(\""+linkVal.rid+"\",\""+linkVal.url+"\")'>" + val + "</a></td>"
        	    	                }else{
        	    	                	 tbody += "<td  class='tdspan'>" + val + "</td>"
        	    	                }
    	                    	}else{
    	                    		 tbody += "<td  class='tdspan'>" + val + "</td>"
    	                    	}
    	                    	
    	                       
    	                    }
    	                   
    	                
    	                    
    	                }
    	               // tbody += "<td  class='tdspan'>" + JOB_STATUS[row['status']].name + "</td>"
    	             
    	                tbody += "</tr>"
    	            }
    	            $("#tbody").html(tbody);
    	     }
   			if (pageinit) {
   			
   				$.jqPaginator('#Pagination',{
   					totalPages : _totalPage,
   					visiblePages : 10,
   					currentPage : 1,
   					prev : '<li class="prev"><a href="javascript:scroll(0,0)">上页</a></li>',
   					next : '<li class="next"><a href="javascript:scroll(0,0)">下页</a></li>',
   					first : '<li class="first"><a href="javascript:scroll(0,0)">首页</a></li>',
   					last : '<li class="last"><a href="javascript:scroll(0,0)">尾页</a></li>',
   					page : '<li class="page"><a href="javascript:scroll(0,0)">{{page}}</a></li>',
   					onPageChange : function(num, type) {
   						if ((this.currentPage != 1)|| (1 != num)) {
   							queryList(num,false);
   						}
   					}
   				});
   			}
    	  })
    	
    }


    function linkPage(rid,url){
    	 var url =  "/action/my/m/show?requestid="+rid+"&mid=a2&aid=ch21";

         window.open(url, 'childWin')
    }
    $(document).ready(function () {

    	queryList(1, true);


        $("#exportExcel").click(function () {
            var requestid = $("#request").val();
            var url = "/action/my/m/exporttmp?type=excel&requestid=" + requestid;

            window.open(url, 'excelWin')

        });

        $("#exportCsv").click(function () {
            var requestid = $("#request").val();
            var url = "/action/my/m/exporttmp?type=csv&requestid=" + requestid;
            window.open(url, 'csvWin')
        });

        $("#exportJson").click(function () {
            var requestid = $("#request").val();
            var url = "/action/my/m/exporttmp?type=json&requestid=" + requestid;
            window.open(url, 'jsonWin')

        });

        



        var op = "";
        for (var i = 0; i < tps.length; i++) {
            if (request_id == tps[i].request_id) {
                op += "<option value=" + tps[i].request_id + " selected>" + tps[i].template_name + "</option>";
            } else {
                op += "<option value=" + tps[i].request_id + ">" + tps[i].template_name + "</option>";
            }

        }
        $("#request").html(op);

        $("#searchBtn").click(function () {
            var requestid = $("#request").val();
            window.location.href = "/action/my/m/show?requestid="+requestid+"&mid=a2&aid=ch21";
           
        });

      
     

    })


</script>

</body>
</html>
